package com.erik.lin.pubsub.listener;

import com.erik.lin.domain.Animal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;

/**
 * Created by Erik on 2017/4/5.
 */
public class PubMessageListener implements MessageListener {

    private static Logger LOG = LoggerFactory.getLogger(PubMessageListener.class);

    @Override
    public void onMessage(Message message, byte[] pattern) {
        JdkSerializationRedisSerializer redisSerializer = new JdkSerializationRedisSerializer();
        Animal whatWeGet = (Animal) redisSerializer.deserialize(message.getBody());
        LOG.info("This is from redis pulish: {}", whatWeGet.toString());
    }
}
